package org.vgr.module.javascript;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import org.alfresco.repo.processor.BaseProcessorExtension;
import org.alfresco.service.cmr.dictionary.TypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public final class TypeScript extends BaseProcessorExtension {
	private static final Log logger = LogFactory.getLog(TypeScript.class);
	private DictionaryService dictionaryService;

	public TypeScript() {
		if (logger.isDebugEnabled()) {
			logger.debug("TypeScript Constructor Called");
		}
	}
	
	protected TypeDefinition getType(String typeName) {
		QName name = QName.createQName(typeName);
		TypeDefinition typeDefinition = this.dictionaryService.getType(name);
		return typeDefinition;
	}
	
	public ArrayList<QName> getTypeProperties(String typeName) {
		TypeDefinition typeDefinition = this.getType(typeName);
		
		Map <QName, PropertyDefinition> properties = typeDefinition.getProperties();
		
		Iterator<QName> propIt = properties.keySet().iterator();
		ArrayList<QName> props = new ArrayList<QName>();
		
		while (propIt.hasNext()) {
			props.add(propIt.next());
		}
		return props;
	}
   
	public void setDictionaryService(DictionaryService dictionaryService) {
		this.dictionaryService = dictionaryService;
	}
}
